unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, UniProvider, PostgreSQLUniProvider, StdCtrls, DBAccess, Uni, DB,
  ADODB, SQLServerUniProvider, MemDS;

type
  TForm1 = class(TForm)
    Btnx_1: TButton;
    Btnx_2: TButton;
    Btnx_3: TButton;
    Btnx_4: TButton;
    Btnx_6: TButton;
    Btnx_7: TButton;
    Btnx_8: TButton;
    Btnx_9: TButton;
    grp1: TGroupBox;
    grp2: TGroupBox;
    UniConnection1: TUniConnection;
    SQLServerUniProvider1: TSQLServerUniProvider;
    ADOConnection1: TADOConnection;
    UniTable1: TUniTable;
    tbl1: TADOTable;
    procedure Btnx_1Click(Sender: TObject);
    procedure Btnx_6Click(Sender: TObject);
    procedure Btnx_2Click(Sender: TObject);
    procedure Btnx_7Click(Sender: TObject);
    procedure Btnx_8Click(Sender: TObject);
    procedure Btnx_3Click(Sender: TObject);
  private
  public
  end;

var
  Form1: TForm1;

implementation

uses
  Class_KzDebug, Class_Card_4ADO, Class_KzUtils, Class_Card_4UNI;


{$R *.dfm}

procedure TForm1.Btnx_1Click(Sender: TObject);
var
  StrsA:TStringList;
begin
  StrsA:=TStringList.Create;
  UniConnection1.GetTableNames(StrsA,False);
  ShowMessage(StrsA.Text);

  FreeAndNil(StrsA);
end;

procedure TForm1.Btnx_6Click(Sender: TObject);
var
  StrsA:TStringList;
begin
  StrsA:=TStringList.Create;
  ADOConnection1.GetTableNames(StrsA,False);
  ShowMessage(StrsA.Text);

  FreeAndNil(StrsA);
end;

procedure TForm1.Btnx_2Click(Sender: TObject);
var
  StrsA:TStringList;
begin
  UniTable1.TableName:='TBL_CARD';
  StrsA:=TStringList.Create;
  UniTable1.GetFieldNames(StrsA);
  ShowMessage(StrsA.Text);

  if StrsA<>nil then
  begin
    FreeAndNil(StrsA);
  end;    
  //ShowMessage(UniTable1.KeyFields);
end;

procedure TForm1.Btnx_7Click(Sender: TObject);
var
  StrsA:TStringList;
begin
  StrsA:=TStringList.Create;
  ADOConnection1.GetFieldNames('TBL_CARD',StrsA);
  ShowMessage(StrsA.Text);

  if StrsA<>nil then
  begin
    FreeAndNil(StrsA);
  end;  
end;

procedure TForm1.Btnx_8Click(Sender: TObject);
var
  cSQL: string;
  cADOD: TADODataSet;
  cList: TStringList;
begin
  cSQL := 'SELECT A.*,B.CARD_NAME,B.CARD_CODE,B.DEPT_LINK,B.ZCLB_LINK,B.CARD_ZJLY,B.CARD_GRRQ,B.CARD_ZCYZ,B.CARD_YJCZ,B.CARD_ZJNX,B.CARD_ZJZT,C.ZCLB_JTBL'
         +'    FROM TBL_CARD_ZJJL A,TBL_CARD B,TBL_ZCLB C    WHERE 1=1    AND A.UNIT_LINK=B.UNIT_LINK    AND A.CARD_IDEX=B.CARD_IDEX    AND A.CARD_BDID=B.CARD_BDID'
         +'    AND B.ZCLB_LINK=C.ZCLB_LINK    AND A.ZJJL_IDEX=1    AND A.ZJJL_YWBZ<>8    AND A.ZJJL_YWBZ<>6    AND A.UNIT_LINK IN ( %s )'
         +'    AND A.CARD_KJND=2019    AND A.CARD_KJQJ=1    ORDER BY A.UNIT_LINK,A.CARD_IDEX,A.CARD_BDID';
  cSQL := Format(cSQL,[QuotedStr('0001-0017')]);


  try
    KzDebug.Started;
    KzDebug.TickLog('ADO_START'); 

    cList := TCARD4ADO.ListDB(cSQL,self.ADOConnection1);
    KzDebug.TickLog('ADO_ENDED');
    KzDebug.TickFmt('ADO_ENDED:%D',[cList.Count]);  
  finally
    TKzUtils.TryFreeAndNil(cList);
  end;

  {try
    KzDebug.Started;
    KzDebug.TickLog('ADO_START');
    cADOD := TADODataSet.Create(nil);
    cADOD.Connection := self.ADOConnection1;
    cADOD.CommandText := cSQL;
    cADOD.Open;
    KzDebug.TickLog('ADO_ENDED');
    KzDebug.TickFmt('ADO_ENDED:%D',[cADOD.RecordCount]);
  finally
    FreeAndNil(cADOD);
  end;}
end;


procedure TForm1.Btnx_3Click(Sender: TObject);
var
  cSQL: string;
  cList: TStringList;
begin
  cSQL := 'SELECT A.*,B.CARD_NAME,B.CARD_CODE,B.DEPT_LINK,B.ZCLB_LINK,B.CARD_ZJLY,B.CARD_GRRQ,B.CARD_ZCYZ,B.CARD_YJCZ,B.CARD_ZJNX,B.CARD_ZJZT,C.ZCLB_JTBL'
         +'    FROM TBL_CARD_ZJJL A,TBL_CARD B,TBL_ZCLB C    WHERE 1=1    AND A.UNIT_LINK=B.UNIT_LINK    AND A.CARD_IDEX=B.CARD_IDEX    AND A.CARD_BDID=B.CARD_BDID'
         +'    AND B.ZCLB_LINK=C.ZCLB_LINK    AND A.ZJJL_IDEX=1    AND A.ZJJL_YWBZ<>8    AND A.ZJJL_YWBZ<>6    AND A.UNIT_LINK IN ( %s )'
         +'    AND A.CARD_KJND=2019    AND A.CARD_KJQJ=1    ORDER BY A.UNIT_LINK,A.CARD_IDEX,A.CARD_BDID';
  cSQL := Format(cSQL,[QuotedStr('0001-0017')]);

  try
    KzDebug.Started;
    KzDebug.TickLog('UNI_START');   
    cList := TStringList.Create;
    TCARD4UNI.ListDB(cSQL,self.UniConnection1,cList);
    KzDebug.TickLog('UNI_ENDED');
    KzDebug.TickFmt('UNI_ENDED:%D',[cList.Count]);      
  finally
    TKzUtils.TryFreeAndNil(cList);
  end;
end;

end.
